


const app = getApp();


Page({

  data:{
    totalAmount: "0.00",
    totalCount: "0",
    bonusList:[],
    pageNo:1,
    loadingHide: false,
    loadingText: "加载中",
    hasNext: false
  },
  onShow: function(){
    console.log("获取userId" + app.data.userid);
    this.data.pageNo = 1;
    this.data.bonusList = [];
    this.getBonusActivityList();
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    }
  },
  onShareAppMessage: function (res) {
    console.log(res);
 
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
      //获取活动的id
      var activityId = res.target.dataset.activityid;
    }
    return {
      title: '自定义转发标题' + activityId,
      path: '/pages/index/index?id=' + activityId,
      success: function(res) {
        // 转发成功
       
        console.log("转发成功");
      },
      fail: function(res) {
        // 转发失败
        console.log("转发失败");
      }
    }
  },
  //获取我的红包列表
  getBonusActivityList: function(){
    var that = this;
    var url = app.data.url + "myCreate.do";
    var dataForm = {
      "type":"my",
      "userId":app.data.userid,
      "pageNo":that.data.pageNo
    };
    app.sendPost(url, dataForm,function(res){
      console.log(res);
      if(res && res.result == "100"){
        var items = {};
        if (res.data){
          items = res.data.items;
        }
        console.log(items);
        that.setData({
          bonusList: that.data.bonusList.concat(items),
          totalAmount: res.data.totalAmount,
          totalCount: res.data.count,
          loadingHide: true,
          hasNext: res.data.next
        });
        
      }
    });
  },
  //打开红包详情
  openBonusDetail: function(res){
    console.log(res);
    var data = res.currentTarget.dataset;
    console.log(data.activityid);
    wx.navigateTo({
      url: '/pages/bonus_detail/bonus_detail?activityid=' + data.activityid,
    })
  },
  //下拉响应事件
  onPullDownRefresh: function () {
    //this.getBonusActivityList();
    //隐藏下拉框
    wx.stopPullDownRefresh();

  },
  //上拉响应事件
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("上拉加载中");
    var that = this;
    if(!that.data.hasNext){
      return;
    }
    that.data.pageNo += 1;
    that.setData({
      pageNo: that.data.pageNo,
      loadingHide: false
    });
    that.getBonusActivityList();
  },

})